<?php
// +----------------------------------------------------------------------
// | When work is a pleasure, life is a joy!
// +----------------------------------------------------------------------
// |User: ShouKun Liu  |  Email:24147287@qq.com  | Time:2017/8/20 15:27
// +----------------------------------------------------------------------
// | TITLE: 账号列表
// +----------------------------------------------------------------------


namespace Qwadmin\Controller;


use Common\Model\AccountModel;

class AccountController extends ComController
{

    protected $accountModel;

    public function _initialize()
    {
        parent::_initialize();
        $this->accountModel = new AccountModel();
    }

    /**
     * 获取账户列表
     */
    public function index()
    {
        // 获取通知信息
        $this->assign('message', S('message'));
        $where['is_delete'] = 0;
        $accountList = $this->accountModel->where($where)->select();
        $this->assign('accountList', $accountList);
        $this->display();

    }

    public function add()
    {
        if (IS_POST) {

            $data = I('');
            $data['user'] = $this->USER['user'];
            $this->accountModel->add($data);
            $this->success('添加成功', U('index'));
        } else {
            $this->display();
        }

    }

    public function edit()
    {
        if (IS_POST) {
            $where['id'] = I('id');
            $data = I('');
            $data['user'] = $this->USER['user'];
            $this->accountModel->where($where)->save($data);
            $this->success('修改成功', U('index'));
        } else {
            $id = I('id');
            $account = $this->accountModel->find($id);
            $this->assign('account', $account);
            $this->display();
        }
    }

    public function openAccount()
    {
        $id = I('id');
        $this->accountModel->openAccount($id, $this->USER['user']);
        $this->success('账号使用开启成功', U('index'));
    }

    public function closeAccount()
    {
        $id = I('id');
        $this->accountModel->closeAccount($id, $this->USER['user']);
        $this->success('账号使用完毕', U('index'));

    }

    public function initAccount()
    {
        $this->accountModel->initAccount();
        $this->success('每天初始化成功', U('index'));
    }

}